package util

import (
	"fmt"
	"strings"
)

const (
	ERC20TransferHash         = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" //crypto.Keccak256Hash([]byte("Transfer(address,address,uint256)"))
	ERC721TransferHash        = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" //crypto.Keccak256Hash([]byte("Transfer(address,address,uint256)"))
	ERC1155TransferSingleHash = "0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62" //crypto.Keccak256Hash([]byte("TransferSingle(address,address,address,uint256,uint256)"))
	ERC1155TransferBatchHash  = "0x4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb" //crypto.Keccak256Hash([]byte("TransferBatch(address,address,address,uint256[],uint256[])"))
	Zero24                    = "000000000000000000000000"
	HexPrefix                 = "0x"
)

func GetETHAddressFromTopic(content string) (string, error) {
	if strings.HasPrefix(content, HexPrefix) && 66 == len(content) {
		return strings.Replace(content, Zero24, "", 1), nil
	} else if !strings.HasPrefix(content, HexPrefix) && 64 == len(content) {
		return HexPrefix + strings.Replace(content, Zero24, "", 1), nil
	} else {
		return "", fmt.Errorf("invalid:%v", content)
	}
}
